package com.zhkj.txg.module.mine.popup

import android.content.Context
import android.view.Gravity
import android.view.View
import android.widget.EditText
import com.zhkj.txg.R
import razerdp.basepopup.BasePopupWindow

class ChangeUserNamePopupWindow(
    context: Context,
    val onConfirm: (content: String) -> Unit
) : BasePopupWindow(context) {

    init {
        popupGravity = Gravity.CENTER
        setAdjustInputMethod(true)
        setAutoShowInputMethod(true)
    }

    private var editText: EditText? = null

    override fun onCreateContentView(): View = createPopupById(R.layout.popup_change_nickname)

    override fun onViewCreated(contentView: View?) {
        editText = contentView?.findViewById(R.id.etMemberNickname)
        contentView?.findViewById<View>(R.id.tvUserNicknameCancel)?.setOnClickListener {
            dismiss()
        }
        contentView?.findViewById<View>(R.id.tvUserNicknameConfirm)?.setOnClickListener {
            onConfirm(editText?.text?.toString() ?: "")
            dismiss()
        }
    }

    fun setOriginNickname(nickName: String) {
        editText?.setText(nickName)
        editText?.setSelection(nickName.length)
        editText?.requestFocus()
    }
}